package cn.com.open.itembank.service;

import cn.com.open.itembank.dto.*;
import cn.com.open.itembank.entity.Question;
import cn.com.open.itembank.exception.PoiException;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Created by lucky on 2017/11/14.
 */
@FeignClient(name = "item-item-service")
public interface ItemRemoteService {

    /**
     * 获取指定试题基本信息.
     *
     * @param id 试题id
     * @return 试题主体模型 full item
     */
    @GetMapping(value = "/question/{id}")
    Question getItem(@PathVariable(value = "id") String id);

    /**
     * 获取指定题库下指定试题不含有qti的信息(paper用)
     *
     * @param itemBankId    题库id
     * @param id            试题id
     * @param includeAnswer 是否包含答案
     * @return 试题模型 item for paper
     */
    @GetMapping(value = "/itembank/{itemBankId}/question/{id}/condition")
    QuestionModel getItemForPaper(@PathVariable("itemBankId") String itemBankId, @PathVariable(value = "id") String id,
                                  @RequestParam("includeAnswer") boolean includeAnswer);

    /**
     * 根据试题数量查询模型获取指定条件下试题数量（策略用）.
     *
     * @param filterModel the filter model
     * @return the question count for rules check
     */
    @PostMapping(value = "/question/rulecheck/count")
    Map<String, Integer> getQuestionCountForRulesCheck(@RequestBody Map<String, QuestionCountFilterModel> filterModel);

    /**
     * 根据试题数量查询模型获取指定条件下试题（策略组卷用）.
     *
     * @param filterModels the filter model
     * @return the question count for rules check
     */
    @PostMapping(value = "/question/rulecheck/questions")
    Map<String, List<RuleQuestionModel>> getQuestionForRule(@RequestBody Map<String, QuestionCountFilterModel> filterModels);

    /**
     * 根据题库id，题型id，所属类别id查询试题id列表（策略组卷用）.
     *
     * @param itemBankId     题库id
     * @param typeCategories 题型,类别map
     * @return the questions by categories for rules
     */
    @PostMapping(value = "/question/rulecheck/categories/questions")
    Map<String, List<String>> getQuestionsByCategoriesForRules(@RequestParam(value = "itemBankId") String itemBankId, @RequestBody Map<String, String> typeCategories);

    /**
     * 根据试题id列表获取策略检查用的试题信息列表（策略检查必选和例题用）.
     *
     * @param itemIds the item ids
     * @return the question info for rule check
     */
    @PostMapping(value = "/question/rulecheck/info")
    List<RuleCheckQuestionInfo> getQuestionInfoForRuleCheck(@RequestBody Map<String, Boolean> itemIds);

    /**
     * 导入逻辑.
     *
     * @param importParameter the input model
     * @return the return model
     * @throws PoiException the poi exception
     */
    @PostMapping(value = "/question/import")
    ReturnModelForTestPaper importLogic(@RequestBody ImportParameter importParameter);

    //region 判断题库和试题是否存在关系

    /**
     * 判断题库和试题是否存在关系.
     *
     * @param itemBankId 题库id
     * @param id         试题id
     * @return the boolean
     */
    @GetMapping(value = "/itembank/{itemBankId}/question/{id}/relation")
    boolean checkItemBankQuestionRelation(@PathVariable("itemBankId") String itemBankId, @PathVariable(value = "id") String id);

    //endregion

    //region 试题主体修改

    /**
     * 试题主体修改
     * @param itemBankId
     * @param questionModel
     * @param questionId
     * @param appKey
     * @return
     */
    @PutMapping(value = "/itembank/{itemBankId}/question/{questionId}")
    ReturnModel updateQuestion(@PathVariable(value = "itemBankId") String itemBankId, @PathVariable(value = "questionId") String questionId,
                               @RequestBody QuestionModel questionModel, @RequestParam("appkey") String appKey);


    //endregion

    //region 新增试题

    /**
     * 新增试题（以itembankid为准替代模型对应数值）.
     *
     * @param itemBankId    题库id
     * @param questionModel 试题录入模型
     * @param appKey        appkey
     * @param source        来源：0，内部；1，外部
     * @return the return model
     */
    @RequestMapping(value = "/itembank/{itemBankId}/question", method = RequestMethod.POST, consumes = "application/json")
    ReturnModel addQuestion(@PathVariable(value = "itemBankId") String itemBankId, @RequestBody QuestionModel questionModel,
                                   @RequestParam("appkey") String appKey, @RequestParam("source") int source);
    //endregion
}
